package com.linln.modules.ad.repository;

import java.util.List;
import com.linln.modules.ad.domain.AdInfo;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;
import com.linln.modules.system.repository.BaseRepository;

/**
 * @author hct
 * @date 2019/09/12
 */
public interface AdInfoRepository extends BaseRepository<AdInfo, Long> {
	
	
	@Modifying
	@Transactional
	@Query("update AdInfo set adStatus = ?1  where id = ?2 ")
	public Integer updateAdStatus(Integer storeStatus, Long id);
	
	
	@Modifying
	@Transactional
	@Query("update AdInfo set readnum = readnum+1  where id = ?1 ")
	public Integer updateIsReadAddById(Long id);
	
	@Query(value="select * from  adinfo where adtypeid = ?1 and area in ( ?2,0) and ad_status=1 and now() between start_time and  end_time ORDER BY id DESC  limit 5 ",nativeQuery=true)
	public List<AdInfo> queryListByTypeAndArea(Integer adtypeid,String area);
	
	@Query(value="select * from  adinfo where adtypeid = ?1 and ad_status=1 and now() between start_time and  end_time ORDER BY id DESC limit 5 ",nativeQuery=true)
	public List<AdInfo> queryListByType(Integer adtypeid);
	
	
	public  AdInfo findByOrderId(String orderId);
	
	
	 /**
	  * 确认已经支付，修改状态
	  * @param orderId
	  * @return
	  */
    @Modifying
    @Transactional
    @Query("update AdInfo set adStatus = 1,payStatus =1  where orderId = ?1 and payStatus=0")
    public Integer updatePayStatus( String orderId);
    

	 /**
	  * 确认退款，修改状态
	  * @param orderId
	  * @return
	  */
   @Modifying
   @Transactional
   @Query("update AdInfo set payStatus =2  where orderId = ?1 and payStatus=1")
   public Integer updateRefundStatus( String orderId);
   
}